package moo.stargalaxy_datasyncs.config;

import moo.stargalaxy_datasyncs.StarGalaxy_DataSyncs;
import moo.stargalaxy_datasyncs.data.SyncsData;
import org.bukkit.configuration.file.YamlConfiguration;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

public class SyncsConfig {
    public static YamlConfiguration yaml;
    public static boolean Enable_SyncLock_Play;

    private static Map<UUID, Boolean> Enable_SyncLock_PlayMap = new HashMap<>();
    private static Map<UUID, Boolean> canGitData = new HashMap<>();
    private static Map<String, SyncsData> syncsDataMap = new LinkedHashMap<>();

    public static void loadYaml(boolean Tis){
        File file = new File(StarGalaxy_DataSyncs.getPlugin().getDataFolder(), "config.yml");
        if(!file.exists()) StarGalaxy_DataSyncs.getPlugin().saveResource("config.yml", false);
        yaml = YamlConfiguration.loadConfiguration(file);
        Enable_SyncLock_Play = yaml.getBoolean("Server_Set.Enable_SyncLock_Play");
        yaml.getConfigurationSection("DataSync_Set").getKeys(false).forEach(s -> {
            SyncsData syncsData = new SyncsData(yaml.getString("DataSync_Set." + s + ".Type"),
                    yaml.getString("DataSync_Set." + s + ".Datasource"),
                    ""
            );
            if (yaml.getConfigurationSection("DataSync_Set." + s).getKeys(false).contains("Datavaluecmd")){
                syncsData = new SyncsData(yaml.getString("DataSync_Set." + s + ".Type"),
                        yaml.getString("DataSync_Set." + s + ".Datasource"),
                        yaml.getString("DataSync_Set." + s + ".Datavaluecmd")
                );
            }
            syncsDataMap.put(s, syncsData);
            // 判断是否进行提醒
            if (Tis){
                StarGalaxy_DataSyncs.getPlugin().getServer().getConsoleSender().sendMessage("§7加载同步项目: §6" + s);
            }
        });
    }

    public static Map<String, SyncsData> getSyncsDataMap() {
        return syncsDataMap;
    }

    public static void setSyncsDataMap(Map<String, SyncsData> syncsDataMap) {
        SyncsConfig.syncsDataMap = syncsDataMap;
    }

    public static YamlConfiguration getYaml() {
        return yaml;
    }

    public static void setYaml(YamlConfiguration yaml) {
        SyncsConfig.yaml = yaml;
    }

    public static boolean isEnable_SyncLock_Play() {
        return Enable_SyncLock_Play;
    }

    public static void setEnable_SyncLock_Play(boolean enable_SyncLock_Play) {
        Enable_SyncLock_Play = enable_SyncLock_Play;
    }

    public static Map<UUID, Boolean> getEnable_SyncLock_PlayMap() {
        return Enable_SyncLock_PlayMap;
    }

    public static void setEnable_SyncLock_PlayMap(Map<UUID, Boolean> enable_SyncLock_PlayMap) {
        Enable_SyncLock_PlayMap = enable_SyncLock_PlayMap;
    }

    public static Map<UUID, Boolean> getCanGitData() {
        return canGitData;
    }

    public static void setCanGitData(Map<UUID, Boolean> canGitData) {
        SyncsConfig.canGitData = canGitData;
    }

    public static Map<UUID, Boolean> getPrevent_LockTime_Sync() {
        return Enable_SyncLock_PlayMap;
    }

    public static void setPrevent_LockTime_Sync(Map<UUID, Boolean> prevent_LockTime_Sync) {
        Enable_SyncLock_PlayMap = prevent_LockTime_Sync;
    }
}
